//package comc.springbatch;
//
//import comc.pojo.LlAppyInfo;
//import org.springframework.batch.core.Job;
//import org.springframework.batch.core.Step;
//import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
//import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
//import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
//import org.springframework.batch.item.ItemProcessor;
//import org.springframework.batch.item.file.FlatFileItemReader;
//import org.springframework.batch.item.file.mapping.DefaultLineMapper;
//import org.springframework.batch.item.file.mapping.FieldSetMapper;
//import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
//import org.springframework.batch.item.file.transform.FieldSet;
//import org.springframework.batch.item.support.CompositeItemProcessor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.core.io.PathResource;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.validation.BindException;
//
//import java.util.ArrayList;
//import java.util.List;
//@Configuration
//@EnableBatchProcessing
//@EnableScheduling
//public class BatchFileTest {
//
//    @Autowired
//    public JobBuilderFactory jobBuilderFactory;
//    @Autowired
//    public StepBuilderFactory stepBuilderFactory;
//    @Autowired
//    public DbWriter dbWriter;
//
//
//    @Bean
//    public Job job4() {
//        return jobBuilderFactory.get("jj072")
//                .start(step4()).listener(new MyJobListener()).build();
//    }
//
//    @Bean
//    public Step step4() {
//        return stepBuilderFactory.get("ss072").
//                chunk(2)
//                .faultTolerant()
//                .listener(new MyChunkListiener())
//                .reader(flatFileItemReader())
//                .writer(dbWriter)
//                .build();
//    }
//    public FlatFileItemReader flatFileItemReader() {
//        FlatFileItemReader reader = new FlatFileItemReader();
//        reader.setResource(new ClassPathResource("llappyinfo.txt"));
//        reader.setLinesToSkip(1);//跳过第一行
//
////        解析数据
//        DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
//        tokenizer.setNames(new String[]{"acceptNo", "batchNo", "rptorName"});
//        tokenizer.setDelimiter(",");
//
////        吧解析出来的数据进行映射为实体类
//        DefaultLineMapper defaultLineMapper = new DefaultLineMapper();
//        defaultLineMapper.setLineTokenizer(tokenizer);
//        defaultLineMapper.setFieldSetMapper(new FieldSetMapper() {
//            @Override
//            public Object mapFieldSet(FieldSet fieldSet) throws BindException {
//                LlAppyInfo llAppyInfo = new LlAppyInfo();
//                llAppyInfo.setAcceptNo(fieldSet.readString("acceptNo"));
//                llAppyInfo.setRptorName(fieldSet.readString("rptorName"));
//                llAppyInfo.setBatchNo(fieldSet.readString("batchNo"));
//                return llAppyInfo;
//            }
//        });
//        defaultLineMapper.afterPropertiesSet();
//        reader.setLineMapper(defaultLineMapper);
//        return reader;
//    }
//
//
//}
